<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/logo.png" alt />
        <span>Vue 做的后台管理项目</span>
      </div>
      <el-button type="info" @click="loginOut">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="iscoll ? '63.99px':'200px'">
        <div @click="iscollspan" class="collsapn">|||</div>
        <el-menu
          background-color="palegreen"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          :collapse-transition="false"
          :collapse="iscoll"
          router
          :default-active='activepath'
        >
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="icons[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item @click="saveActive(subitem.path)" :index="subitem.path" v-for="subitem in item.children" :key="subitem.id">
              <i class="el-icon-menu"></i>
              <span slot="title">{{subitem.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  created() {
    this.leftMenu();
    this.activepath=sessionStorage.getItem('activepath')
  },
  data() {
    return {
      icons: {
        125: "iconfont icon-yonghuguanli",
        103: "iconfont icon-quanxianguanli",
        101: "iconfont icon-RectangleCopy",
        102: "iconfont icon-dingdanguanli",
        145: "iconfont icon-shujutongji"
      },
      menuList: [],
      iscoll: false,
      activepath:''
    };
  },
  methods: {
    async leftMenu() {
      const { data: res } = await this.$http.get(
        "menus"
      );
      this.menuList = res.data;
    },
    loginOut() {
      sessionStorage.clear();
      this.$router.push("/login");
    },
    iscollspan() {
      this.iscoll = !this.iscoll;
    },
    saveActive(activepath){
     this.activepath=activepath
     sessionStorage.setItem('activepath',activepath)
    }
  }
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}
.el-header {
  background-color: tomato;
  display: flex;
  justify-content: space-between;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
    > img {
      width: 60px;
      height: 60px;
    }
    > span {
      font-size: 20px;
      letter-spacing: 0.2em;
      margin-left: 50px;
      font-weight: 700;
      color: white;
    }
  }
}
.el-aside {
  background-color: palegreen;
  .el-menu{
      border-right: none;
  }
  .collsapn {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: white;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
}
.el-main {
  background: papayawhip;
}
.iconfont {
  margin-right: 10px;
}
</style>